﻿@using KPIS.GERP.Models.ICM
@model PurchaseOrderPenalty

@{
    ViewBag.Title = "สร้างกำหนดปรับ";
    ViewBag.Descr =  ViewBag.Title+" เพื่อกำหนดปรับงานใบสั่ง";
   // int intPoId = ViewBag.PoId;

    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
}

@using (Html.BeginForm("Create", "Penalty", FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()
    <p id="message"></p>
    <div class="block-button-menu-above">
         @Html.ActionLink("กลับไปหน้าแสดงข้อมูลทั้งหมด", "Index", new { PoId = Model.PoId }, new { @class = "btn btn-gray button-standard-width btn-small", role="button" })
       
        @Html.ButtonSubmit()
    </div>
    
   <div class="alert-error">@Html.ValidationSummary()</div>
    @Html.Partial("_EditorForm")

}


@section scripts
{
    
      <script>

          $("form").not("#formsearch").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm("ท่านต้องการยืนยัน ใช่หรือไม่", function (result) {
                if (result) {
                    // currentForm.submit();
                    $.ajax({
                        url: "Create",
                        type: "post",
                        dataType: "json",
                        data: $(currentForm).serialize(),
                        success: function (result) {
                            console.log(result.success);
                            console.log(result.confirm);
                            if (result.success) {
                               
                                window.setTimeout(function () {
                                    $("#message").html(result.message);
                                    window.location.href = '@Url.Action("Details", "Penalty")/' + result.id;
                                }, 1000);
                            }
                            else {
                                $("#message").html(result.message);
                               //  $("#loading").hide();
                            }
                        }
                    });
                }
            });
        });


        //$(function () {
        //    ChangeEnableDurType();
        //});

       // $('input[type=radio]').change(ChangeEnableDurType);

        //function ChangeEnableDurType() {
        //    if ($('#durType2radio').is(':checked')) {
        //        $('#PurchaseOrder_RequireDuration').attr('disabled', '');
        //        $('#PurchaseOrder_DurTypeId').attr('disabled', '');
        //       // $('#DurCountId').attr('disabled', '');
        //        $('#PurchaseOrder_RequireDate').removeAttr('disabled');
        //    } else {
        //        $('#PurchaseOrder_RequireDuration').removeAttr('disabled');
        //        $('#PurchaseOrder_DurTypeId').removeAttr('disabled');
        //     //   $('#DurCountId').removeAttr('disabled');
        //        $('#PurchaseOrder_RequireDate').attr('disabled', '');
        //    }
        //}
    </script>
}
